package com.ruoyi.review.controller;

import java.io.Console;
import java.io.File;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.review.domain.AReviewBatch;
import com.ruoyi.review.domain.ReviewUserLotVo;
import com.ruoyi.review.domain.AReviewObject;
import com.ruoyi.review.domain.AWordManage;
import com.ruoyi.review.service.IAReviewBatchService;
import com.ruoyi.review.service.IAReviewObjectService;
import com.ruoyi.review.service.IAWordManageService;
import com.ruoyi.review.vo.BatchVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2024-06-08
 */
@RestController
@RequestMapping("/review/batch")
public class AReviewBatchController extends BaseController
{
    @Autowired
    private IAReviewBatchService aReviewBatchService;
    @Autowired
    private IAReviewObjectService aReviewObjectService;
    @Autowired
    private IAWordManageService aWordManageService;

    /**
     * 查询【请填写功能名称】列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AReviewBatch aReviewBatch)
    {
        startPage();
        List<AReviewBatch> list = aReviewBatchService.selectAReviewBatchList(aReviewBatch);
        return getDataTable(list);
    }

    /** 查询评审人相关信息*/
    @GetMapping("/ReviewUserDetails")
    public TableDataInfo ReviewUserDetails(){
        startPage();
        List<ReviewUserLotVo> getlist = aReviewBatchService.getList();
        return getDataTable(getlist);
    }

    /** */
    @GetMapping("/BatchList")
    public TableDataInfo BatchList(){
        startPage();
        List<AReviewBatch> reviewBatchList = aReviewBatchService.getReviewBatchList();
        return getDataTable(reviewBatchList);
    }
    /** */
    @GetMapping("/ReviewList")
    public TableDataInfo ReviewList(){
        startPage();
        List<ReviewUserLotVo> getlist = aReviewBatchService.getReviewUsers();
        return getDataTable(getlist);
    }
    /** */
    @GetMapping("/saveBatchAndReviewUsers")
    public AjaxResult ReviewUserDetails(ReviewUserLotVo vo){
//        logger.debug("===============ReviewUserLotVo=========={}", JSONUtils.toJSONString(vo));
        aReviewBatchService.saveReviewsAndBatchUser(vo);
        return AjaxResult.success();
    }
    /**
     * 导出【请填写功能名称】列表
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AReviewBatch aReviewBatch)
    {
        List<AReviewBatch> list = aReviewBatchService.selectAReviewBatchList(aReviewBatch);
        ExcelUtil<AReviewBatch> util = new ExcelUtil<AReviewBatch>(AReviewBatch.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @GetMapping(value = "/{batchId}")
    public AjaxResult getInfo(@PathVariable("batchId") Long batchId)
    {
        return success(aReviewBatchService.selectAReviewBatchByBatchId(batchId));
    }

    /**
     * 新增【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BatchVo batchVo)
    {
        aReviewBatchService.insertAReviewBatch(batchVo.getaReviewBatch());
        Long batchId = batchVo.getaReviewBatch().getBatchId();

        for (AWordManage word: batchVo.getaWordManageList()) {
            AReviewObject reviewObject = new AReviewObject();
            reviewObject.setBatchId(batchId);
            reviewObject.setObjectName(word.getWordName());

            aReviewObjectService.insertAReviewObject(reviewObject);

            word.setObjectId(reviewObject.getObjectId());
            aWordManageService.insertAWordManage(word);

        }
        return AjaxResult.success();
    }

    /**
     * 修改【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AReviewBatch aReviewBatch)
    {
        return toAjax(aReviewBatchService.updateAReviewBatch(aReviewBatch));
    }

    /**
     * 删除【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{batchIds}")
    public AjaxResult remove(@PathVariable Long[] batchIds)
    {
        return toAjax(aReviewBatchService.deleteAReviewBatchByBatchIds(batchIds));
    }


}
